﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using System.ComponentModel;

namespace BE
{
    public class ControlInfo
    {
        public string Name { get; set; }
        private string fullName;
        // Summary:
        //      Fullname is composed by Form.(Optional)parentcontrolName.Componentname
        //      Parentcontrol is optional and will only be present if the component lies in some sort of list for example: microsoft treeview, teleriks treeview, Teleriks listbox 
        public string FullName
        {
            get
            {
                if(fullName==null)
                return FormName + ((parentControl == null) ? "." : "." + parentControl + ".") + Name;
                return fullName;
            }
            set { fullName = value; }
        }
        [DefaultValue(true)]
        public bool AddToDb { get; set; } // if the text is a master changed on a tag the text should not be added to the database and this will be set to false
        public int Tag { get; set; }
        public string Text { get; set; }
        public string parentControl { get; set; } // for controls who are children of a parent that contains some items which might not be saved in the database
        public string FormName { get; set; } //the form to which this controlinfo belongs to, saved as FormInstance().GetType().ToString()
        private int _list;
        private int _index;
        public int list
        {
            get { return _list; }
            set
            {
                IsParent = false;
                _list = value;
            }
        } // in which list of askables this control lies
        public int index { get { return _index; } set { IsParent = false; _index = value; } }//the dictionary index in which this control lies
        //askables is like a two dimensional Dictionary first the list the controlinfo is in is indexed then in this dictionary is another dictionary with integer indexes so finding the controlinfo will be askables[list][index]
        public string ParentType{get;set;}
        public bool simpleTagged = true;
        public bool isForm = false;
       // public bool newMaster = false;
       public bool IsParent; // til fremtidig implementering af checkning om dette controlinfo er parent selvom det ikke er i askables
             

        public ControlInfo()
        {
            Tag = 0;
            _list = 0;
            _index = 0;
           
            IsParent = true;
            AddToDb = true;
        }
        // Summary:
        //     Create a new Controlinfo Object using either
        //     RadItem or Control for the o parameter
        public ControlInfo(object tag, Object o, string Formname)
        {
            IsParent = true;
            AddToDb = true;
            Tag = 0;
            _list = 0;
            _index = 0;
            parentControl = null;
            FormName = Formname;
            if (o is RadItem)
            {
                RadItem ele = (RadItem)o;
                if ( ele.Tag != null && ele.Tag is int) //checker om tagget ikke er null og om det er et integer siden .Tag er af typen object i komponenterne
                    Tag = (int)tag;
                Name = ele.Name;
                Text = ele.Text;
            }
            if (o is Control)
            {
                Control ct = (Control)o;
                if (ct.Tag != null && ct.Tag is int)
                    Tag = (int)tag;
                Name = ct.Name;
                Text = ct.Text;
            }

        }

        
    }

}
